package com.tongji.housediy.view
{
	import com.tongji.housediy.events.commonEvent.MouseEnabledAdminEvent;
	import com.tongji.housediy.events.commonEvent.RoomNameAdminEvent;
	import com.tongji.housediy.events.commonEvent.RulerAdminEvent;
	import com.tongji.housediy.events.commonEvent.ShowHideTitleWindowEvent;
	import com.tongji.housediy.model.FloorModel;
	import com.tongji.housediy.utils.DragDropManager;
	import com.tongji.housediy.view.components.AbstractDrawingRoom;
	import com.tongji.housediy.view.components.SpecificRoom;
	
	import flash.events.MouseEvent;
	
	import mx.events.DragEvent;
	
	import org.robotlegs.mvcs.Mediator;
	
	import spark.components.Group;
	import spark.filters.DropShadowFilter;
	import spark.filters.GlowFilter;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class ScrollingRoomMediator extends Mediator
	{
		[Inject]
		public var view:ScrollingRoomContent;
		
		override public function onRegister():void
		{
			view.addEventListener(MouseEvent.MOUSE_DOWN, listMouseDownHandler);
			view.addEventListener(MouseEvent.MOUSE_OVER, listMouseOverHandler);
			view.addEventListener(MouseEvent.MOUSE_OUT, listMouseOutHandler);
			
			view.addEventListener(DragEvent.DRAG_COMPLETE, listDragCompleteHandler);
		}
		
		private function listMouseDownHandler(event:MouseEvent):void
		{
			if (!(event.target is ScrollingRoomContent))
			{
				//dispatch(new RulerAdminEvent(RulerAdminEvent.HIDE_ALL_RULERS));
				dispatch(new ShowHideTitleWindowEvent(ShowHideTitleWindowEvent.HIDE_TITLE_WINDOW));
				dispatch(new MouseEnabledAdminEvent(MouseEnabledAdminEvent.MOUSE_ENABLED_CLOSED));
				dispatch(new RoomNameAdminEvent(RoomNameAdminEvent.HIDE_ROOM_NAME));
				
				var roomProxy:AbstractDrawingRoom = new SpecificRoom(view.getChildIndex(event.target as Group));
				DragDropManager.startDragRoom(view, event, roomProxy);
			}
		}
		
		private function listMouseOverHandler(event:MouseEvent):void
		{
			if (!(event.target is ScrollingRoomContent))
			{
				(event.target as Group).filters = [new DropShadowFilter()];
			}
		}
		
		private function listMouseOutHandler(event:MouseEvent):void
		{
			if (!(event.target is ScrollingRoomContent))
			{
				(event.target as Group).filters = null;
			}
		}
		
		private function listDragCompleteHandler(event:DragEvent):void
		{
			dispatch(new MouseEnabledAdminEvent(MouseEnabledAdminEvent.MOUSE_ENABLED_OPENED));
		}
	}
}